import http from 'wechat-http'
http.baseURL = 'https://live-api.itheima.net/'
http.intercept.request = (req) => {
  req.header = {
    Authorization: 'Bearer ' + wx.getStorageSync('token') || '',
    ...req.header,
  }
  return req
}
http.intercept.response = (res) => {
  if (res.data.code === 10000) {
    return res.data
  } else {
    wx.utils.toast(res.data.message || '请求失败')
    wx.removeStorageSync('token')
    wx.removeStorageSync('refreshToken')
    return Promise.reject(res.data)
  }
}
export default http
